﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Applee.FractCommon;
using System.Drawing;

namespace Applee.FractManager
{
    public class FractManager
    {
        private static FractManager mInstance = new FractManager();
        public static FractManager Instance
        {
            get { return FractManager.mInstance; }
        }

        private IDrawable mDrawable = null;
        public IDrawable Drawable
        {
            get { return mDrawable; }
        }

        protected Size mViewSize = new Size();
        public Size ViewSize
        {
            set { mViewSize = value; }
        }

        public void CreateFract(string strName, float length, int iterations)
        {
            try
            {
                mDrawable = FractFactory.CreateFract(strName);

                IFractable fractable = mDrawable as IFractable;
                fractable.ViewSize = mViewSize;

                fractable.CreateFract(length, iterations);
            }
            catch (Exception)
            {
            }
        }

        public string[] Initialize()
        {
            FractConf instance = FractConf.Instance;
            return instance.GetNames();
        }

        public void RefreshFract(string p, float length, int iterations)
        {
            try
            {
                IFractable fractable = mDrawable as IFractable;
                fractable.ViewSize = mViewSize;
                fractable.CreateFract(length, iterations);
            }
            catch (Exception)
            {
            }
        }
    }
}
